package config;


import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

public class AppConfig {

	private final static Properties prop = new Properties();
	private static InputStream in;
	
	private static String protocol="";
	private static String baseUrl = "";
	private static String appName = "";
	private static String appURL= "";

	
	private static AppConfig conf;
	
	private AppConfig()
	{
	}

	
/*	private static AppConfig getInstance() 
	{
		if(conf==null)
		{
			conf = new AppConfig();
		}
		return conf;		
	}*/
	
	public static AppConfig getParams(String applicationName) throws Exception
	{
		if(AppConfig.conf==null)
		{
			AppConfig.conf = new AppConfig();
		}
		
		
		String properitiesPath="";
		if (applicationName.toLowerCase().equals("ap-mzwi"))
		{
			properitiesPath="/apps/ap-mzwi.properties";
		} else 
		{
			throw new Exception ("Brak konfiguracji dla / nieznana aplikacja " + applicationName);
		}		
		
		in = conf.getClass().getResourceAsStream(properitiesPath);
		prop.load(in);
		
		
	    Enumeration<?> e = prop.propertyNames();

	    System.out.println("USTAWIENIA:  ");
	    while (e.hasMoreElements()) {
	      String key = (String) e.nextElement();
	      System.out.println("KEY:  " + key.trim() + "  =  " + prop.getProperty(key));

	      if (key.equals("protocol")) 
	      {
	    	  protocol=prop.getProperty(key).trim();
	      }
	      else if (key.equals("baseUrl")) 
	      {
	    	  baseUrl=prop.getProperty(key).trim();
	      }
	      else if (key.equals("appName")) 
	      {
	    	  appName=prop.getProperty(key).trim();
	      }
	      else if (key.equals("appURL")) 
	      {
	    	  appURL=prop.getProperty(key).trim();
	      }
	    }
		return conf;
	}

	
	public String getProtocol() {
		return protocol.trim();
	}

	public String getBaseUrl() {
		return baseUrl.trim();
	}

	public String getAppName() {
		return appName.trim();
	}

	public String getAppURL() {
		return appURL.trim();
	}



	



	
}
